Skip to content

feat: add DocumentProperties option for setting document metadata#78

Merged
vaceslav merged 3 commits intomainfrom
feature/77-document-properties
Feb 13, 2026
Merged

feat: add DocumentProperties option for setting document metadata#78
vaceslav merged 3 commits intomainfrom
feature/77-document-properties

Conversation

@vaceslav
Copy link
Contributor

Summary

  • Add DocumentProperties class with 7 metadata fields (Author, Title, Subject, Description, Keywords, Category, LastModifiedBy)
  • Add DocumentProperties? option to PlaceholderReplacementOptions — null properties preserve original template values, non-null values overwrite
  • Apply properties via document.PackageProperties as a post-processing step in DocumentTemplateProcessor

Closes #77

Test plan

  • Set Author only → verify Author changed, other props preserved
  • Set all 7 properties → verify all set correctly
  • No DocumentProperties (null) → original Author preserved (backward compat)
  • DocumentProperties with all nulls → all original values preserved
  • Empty string Author → sets to empty (explicit clear)
  • Works alongside placeholder replacement
  • All 971 tests pass
  • dotnet format --verify-no-changes clean

Add ability to set Author, Title, Subject, Description, Keywords,
Category, and LastModifiedBy on output documents via
PlaceholderReplacementOptions.DocumentProperties.
Make ApplyDocumentProperties static, add null-origin test case, and
document the DocumentProperties feature in README, Examples, and
quick-start guide.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds support for setting document metadata properties (Author, Title, Subject, Description, Keywords, Category, LastModifiedBy) when processing Word templates. The feature allows consumers to override or set document properties programmatically while preserving original template values for properties left as null.

Changes:

  • Added DocumentProperties class with 7 metadata fields as nullable, init-only properties
  • Extended PlaceholderReplacementOptions with optional DocumentProperties parameter
  • Implemented ApplyDocumentProperties method in DocumentTemplateProcessor as a post-processing step

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
TriasDev.Templify/Core/DocumentProperties.cs New sealed class defining 7 document metadata properties with XML documentation
TriasDev.Templify/Core/PlaceholderReplacementOptions.cs Added nullable DocumentProperties property to configuration options
TriasDev.Templify/Core/DocumentTemplateProcessor.cs Added ApplyDocumentProperties method that maps properties to OPC PackageProperties
TriasDev.Templify.Tests/Integration/DocumentPropertiesTests.cs Comprehensive integration tests covering all scenarios (7 tests)
TriasDev.Templify.Tests/Helpers/DocumentBuilder.cs Added SetAuthor, SetTitle, SetSubject methods for test document setup
TriasDev.Templify.Tests/Helpers/DocumentVerifier.cs Added 7 getter methods for verifying document properties in tests
docs/for-developers/quick-start.md Added documentation section explaining DocumentProperties usage with example
TriasDev.Templify/README.md Added comprehensive documentation with behavior explanation, property mapping table, and examples
TriasDev.Templify/Examples.md Added new section with examples of setting document properties

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1778 to +1790
```csharp
var options = new PlaceholderReplacementOptions
{
Culture = new CultureInfo("de-DE"),
UpdateFieldsOnOpen = UpdateFieldsOnOpenMode.Auto,
DocumentProperties = new DocumentProperties
{
Author = "Rechnungssystem",
Title = $"Rechnung {invoiceNumber}",
LastModifiedBy = "Templify"
}
};
```
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code example is missing the required using System.Globalization; statement for CultureInfo, and the variable invoiceNumber is used in the string interpolation but is not declared or defined anywhere in the example. This would cause compilation errors if a user tries to use this code as-is.

Copilot uses AI. Check for mistakes.
/// <summary>
/// Gets or initializes the document metadata properties to set on the output document.
/// When null (default), the original template properties are preserved unchanged.
/// Only non-null property values within <see cref="Core.DocumentProperties"/> are applied;
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The XML documentation comment uses Core.DocumentProperties with a namespace prefix, but since both PlaceholderReplacementOptions and DocumentProperties are in the same TriasDev.Templify.Core namespace, the prefix is unnecessary. For consistency with other references in this file (e.g., line 17 uses MissingVariableBehavior without prefix, line 119 uses PlaceholderReplacementOptions without prefix), it should be just DocumentProperties instead of Core.DocumentProperties.

Suggested change
/// Only non-null property values within <see cref="Core.DocumentProperties"/> are applied;
/// Only non-null property values within <see cref="DocumentProperties"/> are applied;

Copilot uses AI. Check for mistakes.
Remove unnecessary namespace prefix in see cref, and add missing
using statement and variable declaration in Examples.md code sample.
@vaceslav vaceslav merged commit a31038b into main Feb 13, 2026
14 checks passed
@vaceslav vaceslav deleted the feature/77-document-properties branch February 13, 2026 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for setting document properties (Author, Title, etc.) after rendering

2 participants